<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class AddForeignKeysToCommentsTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('comments', function(Blueprint $table)
        {
            $table->foreign('parent_id')->references('id')->on('comments')->onUpdate('CASCADE')->onDelete('SET NULL');
            $table->foreign('post_id')->references('id')->on('posts')->onUpdate('CASCADE')->onDelete('SET NULL');
        });
    }


    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('comments', function(Blueprint $table)
		{
			$table->dropForeign('comments_parent_id_foreign');
			$table->dropForeign('comments_post_id_foreign');
		});
	}

}
